package graphics.view2D;

import model.Piece;
import graphics.interfaces.IDrawable;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Piece2D implements IDrawable {
	private Piece type;
	private Sprite sprite;
	private Texture pieceSet;
		
	public Piece2D(Piece type, String chessSet2D){
		this.type = type;
		this.pieceSet = new Texture(Gdx.files.internal("data/images/sets/set2D/" + chessSet2D));
		LoadContent();
	}
	
	public void LoadContent() {
		
		Color customWhite = new Color(1f, 0.3f, 0.3f, 1f);
		Color customBlue = new Color(0.3f, 0.3f, 1f, 1f);
		
		switch(type){
			case WP: this.sprite = new Sprite(this.pieceSet, 0, 0, 60, 60); this.sprite.setColor(customWhite); break;
			case WR: this.sprite = new Sprite(this.pieceSet, 60, 0, 60, 60); this.sprite.setColor(customWhite); break;
			case WN: this.sprite = new Sprite(this.pieceSet, 120, 0, 60, 60); this.sprite.setColor(customWhite); break;
			case WB: this.sprite = new Sprite(this.pieceSet, 0, 60, 60, 60); this.sprite.setColor(customWhite); break;
			case WQ: this.sprite = new Sprite(this.pieceSet, 60, 60, 60, 60); this.sprite.setColor(customWhite); break;
			case WK: this.sprite = new Sprite(this.pieceSet, 120, 60, 60, 60); this.sprite.setColor(customWhite); break;
			case BP: this.sprite = new Sprite(this.pieceSet, 0, 0, 60, 60); this.sprite.setColor(customBlue); break;
			case BR: this.sprite = new Sprite(this.pieceSet, 60, 0, 60, 60); this.sprite.setColor(customBlue); break;
			case BN: this.sprite = new Sprite(this.pieceSet, 120, 0, 60, 60); this.sprite.setColor(customBlue); break;
			case BB: this.sprite = new Sprite(this.pieceSet, 0, 60, 60, 60); this.sprite.setColor(customBlue); break;
			case BQ: this.sprite = new Sprite(this.pieceSet, 60, 60, 60, 60); this.sprite.setColor(customBlue); break;
			case BK: this.sprite = new Sprite(this.pieceSet, 120, 60, 60, 60); this.sprite.setColor(customBlue); break;
			default : break;
		}
	}
	
	public void Draw(SpriteBatch spriteBatch) {
		this.sprite.draw(spriteBatch);
	}
		
	/*
	 * Place graphiquement la piece en fonction de la colonne/ligne sur le tableau de jeu
	 */
	public void SetPosition(int x, int y){
		this.sprite.setPosition(x, y);
	}
}
